<?php
/**
 * 
 * [2009-05-26] Implement Feature Request 2777528 <a href="http://sourceforge.net/tracker/?func=detail&amp;aid=2777528&amp;group_id=214107&amp;atid=1028362">Global Filter</a>
 * <filter id="glbFilter" class="" type="global">
 * 	<exclude id="excludeActionId1"/>
 *  <exclude id="excludeActionId2"/>
 * </filter>
 * @author Milo Liu
 *
 */
class FilterConfig {
	
	//[2009-05-26] Implement Feature Request 2777528
	//----------------------------------------------
	const TYPE_GLOBAL = 'global';
	const TYPE_DEFAULT = 'default';
	
	public $id;

	public $clzName;

	public $results;
	
	//[2009-05-26] Implement Feature Request 2777528
	//----------------------------------------------
	/**
	 * Type of a filter, includes:
	 * <ol>
	 * 	<li> GLOBAL - global filters, would be called for all actions</li>
	 *  <li> DEFAULT - default filters, would be called for the action that include the filter</li>
	 * </ol>
	 * @var string
	 */
	public $type = FilterConfig::TYPE_DEFAULT;
	
	/**
	 * A list of action id, which related actions would ignore this global filter
	 * @var array
	 */
	public $excludes = array();	

	public function toXml(){
		$outXml = "<filter id=\"".$this->id."\" class=\"".$this->clzName."\" type=\"".$this->type."\">";

		foreach($this->results as $result){
			$outXml .= $result->toXml();
		}

		foreach($this->excludes as $actionId){
			$outXml .= "<exclude id=\"$actionId\"/>";
		}
		$outXml .= "</filter>";
		return $outXml;
	}
}

